﻿/*
 * 由SharpDevelop创建。
 * 用户： Administrator
 * 日期: 2015/12/1
 * 时间: 13:50
 * 
 * 要改变这种模板请点击 工具|选项|代码编写|编辑标准头文件
 */
using System;
using System.Windows.Forms;
using System.Security.Principal;
using System.Diagnostics;
namespace df
{
    /// <summary>
    /// Class with program entry point.
    /// </summary>
    internal sealed class Program
    {
        /// <summary>
        /// Program entry point.
        /// </summary>
        [STAThread]
        private static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            try
            {

                //Application.Run(new login());return;


                welcome w = new welcome();

                if (w.ShowDialog() == DialogResult.OK)
                {

                    Application.Run(new MainForm());
                }
                //主线程把对象里的所有代码执行完成之后才会执行show

                //AdminRun(new MainForm());


            }
            catch
            {
                
            }
        }


        //以超级管理员运行程序
        //xx x = new xx();   x.AdminRun(new MainForm());
        public static void AdminRun(System.Windows.Forms.Form NewMainForm)
        {
            WindowsIdentity current = WindowsIdentity.GetCurrent();
            WindowsPrincipal windowsPrincipal = new WindowsPrincipal(current);
            if (windowsPrincipal.IsInRole(WindowsBuiltInRole.Administrator))
            {
                System.Windows.Forms.Application.Run(NewMainForm);
            }
            else
            {
                Process.Start(new ProcessStartInfo
                {
                    FileName = System.Windows.Forms.Application.ExecutablePath,
                    Verb = "runas"
                });
            }
        }



    }
}
